<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8" />
	<link rel="stylesheet" href="css/form.css" />
</head>

<body>
	<div id="header-wrap" data-mn="0">
		<a href="###" data-link="back" data-type="ico" class="left ico-m ico-left"></a>
		<h2>充值</h2>
		<!-- <a href="###" data-link="tariff" class="right btn b-small b-red">说明</a> -->
	</div>
	<div style="">
		<div class="tips">
			<div class="t-info"></div>
			<div class="t-error"></div>
		</div>
		<form>
		
		<ul class="form-list" id="first_pay">
			<li class="ico-m ico-pl ico-card" data-type="ico" id="bcard_code">
				<div class="fl-cont form-input f-right-btn">
					<input type="number" id="card_number" placeholder="请输入银行卡号" value="6222600620011234" />
					<span class="right" id="bank_name" style="display: none;">工商银行</span>
				</div>
			</li>
			<li class="ico-m ico-pl ico-red ico-rmb" data-type="ico">
				<div class="fl-cont form-input">
					<input type="number" id="recharge" placeholder="请输入充值金额" value="" />
				</div>
			</li>
		</ul>
		<div id="id_info">
			<h3 style="padding: 10px;text-align: center;">银行预留信息必须与实名认证信息一致</h3>
			<ul class="label-list c-right">
				<li class="">
					<label>姓名</label>
					<div class="ll-cont"><span id="id_name"></span></div>
				</li>
				<li class="">
					<label>身份证</label>
					<div class="ll-cont"><span id="id_code"></span></div>
				</li>
			</ul>
		</div>
		<div class="fixed-btn">
			<a href="first-pay.html" class="btn b-red"><span id="check">充值</span></a>
		</div>
		<div id="bank-card">
			<div class="card-wrap">
				<span class="bico-gongshangyinhang" ></span>
				<h3 id="">中国工商银行借记卡</h3>
				<b id="card_code"></b>
				<em id="card_name"></em>
			</div>
		</div>
		</form>
	</div>
	<script>
	$(function(){
		var id = $.cookie("id_show");
		var bcard = $.cookie("bc_show");
		var name = $.cookie("name_show");
		if(id == undefined){//没实名认证
			$("#bank-card").remove();
			alert("充值前需要先完成实名认证！");
			load_page("edit-id")
			return false
		}else{//实名认证过
		
			$("#recharge").on("keyup",function(){
				var val = parseInt($(this).val(),10)
				$(this).val(val)
			})
			if(bcard == undefined){//但是没有绑卡，首次支付
				$(".t-info").text("首次支付，需要输入银行卡号，支付完成后该卡将被绑定")
				$("#bank-card").remove();
				$("#id_name").text(name);
				$("#id_code").text(id);
				$(".t-info").html("首次充值使用的银行卡将被绑定<br />同一个用户、同时只能绑定一张银行卡");
				$("#card_number").on("keyup",function(){
					var len = $(this).val().length;
					if(len > 5 && len <20){
						$("#bank_name").fadeIn(200)
					}else{
						$("#bank_name").hide()
					}
				})
				$("#check").on("click",function(){
					var rech = $("#recharge").val();
					if(rech == ''){
						$(".t-error").text("充值金额不能为空").fadeIn(100)
						$(".t-info").hide();
						reset_tip()
						return false
					}
					
					var card_number = $("#card_number").check({type:4});
					var rech_temp = $("#recharge").check({type:8});
					if(card_number == 0){
						$(".t-error").text("请输入有效银行卡号").fadeIn(100)
						$(".t-info").hide();
						reset_tip()
						return false
					}else if (rech_temp == 0){
						$(".t-error").text("请输入有效金额").fadeIn(100)
						$(".t-info").hide();
						reset_tip()
						return false
					}else{
						var card_code = $("#card_number").val()
						var recharge_temp = $("#recharge").val()
						$.cookie("cb_temp",card_code);
						$.cookie("recharge_temp",recharge_temp);
						$.cookie("recharge_bind",1);
					}
				})
				
			}else{//曾经支付过，有银行卡记录
				$("#check").parent(".btn").attr("href","###").attr("data-link","recharge-2")
				$(".t-info").text("已绑定银行卡")
				$("#bcard_code,#id_info").remove();
				$("#card_code").text(bcard);
				$("#card_name").text(name);
				$("#check").on("click",function(){
					var rech = $("#recharge").val();
					var rech_temp = $("#recharge").check({type:8});
					if(rech == ''){
						$(".t-error").text("充值金额不能为空").fadeIn(100)
						$(".t-info").hide();
						reset_tip()
						return false
					}
					if (rech_temp == 0){
						$(".t-error").text("请输入有效金额").fadeIn(100)
						$(".t-info").hide();
						reset_tip()
						return false
					}else{
						var recharge_temp = Number($("#recharge").val())
						var balance;
						if($.cookie("balance") == undefined){
							balance = 0;
						}else{
							balance = Number($.cookie("balance"))
						}
						$.cookie("recharge_temp",recharge_temp);
						$.cookie("balance",recharge_temp+balance);
						$.cookie("recharge_bind","",{expires: -1});
					}
				})
			}
		}
	})
	</script>	
</body>

</html>
